public class Solution226 {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public TreeNode invertTree(TreeNode root) {
        if (root==null){
            return null;
        }
        TreeNode node1=root.left;
        TreeNode node2=root.right;
        root.left=invertTree(node2);
        root.right=invertTree(node1);
        return root;
    }

    public static void main(String[] args) {
        System.out.println(new Solution226().invertTree(new TreeNode(4,new TreeNode(2,new TreeNode(1),new TreeNode(3)),new TreeNode(7,new TreeNode(6),new TreeNode(9)))).left.left.val);
    }
}
